<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #252525;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #ffffde;
            gap: 0 12px;
        }

        .container {
            background-color: inherit;
            position: relative;
            display: flex;
            align-items: center;
            flex-direction: column;
            overflow: hidden;
            width: 100px;
            height: 300px;
            mask-image: linear-gradient(180deg,
                    transparent,
                    #fff 20%,
                    #fff 80%,
                    transparent);
            /* mask-image: linear-gradient(180deg, transparent, #000 20%, #000 80%, transparent); */
            /* background-image: linear-gradient(180deg, transparent, blue 20%, purple 80%, transparent); */
        }

        .container div {
            white-space: nowrap;
            display: flex;
            flex-direction: column;
            animation: scrollUp var(--t) linear infinite;
            user-select: none;
        }

        .container div:nth-child(2) {
            animation: scrollUp2 var(--t) linear infinite;
            animation-delay: calc(var(--t) / -2);
            user-select: none;
        }

        @keyframes scrollUp {
            from {
                transform: translateY(100%);
            }

            to {
                transform: translateY(-100%);
            }
        }

        @keyframes scrollUp2 {
            from {
                transform: translateY(0%);
            }

            to {
                transform: translateY(-200%);
            }
        }

        .container div span {
            display: inline-flex;
            background-color: #333;
            letter-spacing: 0.2em;
            margin: 10px;
            border-radius: 5px;
            padding: 5px 10px;
        }
    </style>
</head>

<body>
    <!-- 第一列 -->
    <div class="container" style="--t: 16s">
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
    </div>

    <div class="container" style="--t: 12s">
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
    </div>

    <div class="container" style="--t: 8s">
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
    </div>

    <div class="container" style="--t: 4s">
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
        <div>
            <span>Lorem1</span>
            <span>Lorem2</span>
            <span>Lorem4</span>
            <span>Lorem5</span>
            <span>Lorem6</span>
            <span>Lorem7</span>
            <span>Lorem8</span>
            <span>Lorem9</span>
        </div>
    </div>
</body>
<script>
    const containers = document.querySelectorAll(".container");

    containers.forEach((container) => {
        const divs = container.querySelectorAll("div");
        let isDragging = false;
        let startY, initialTranslateY = 0, currentTranslateY = 0;

        // 停止拖动的通用方法
        function stopDragging() {
            isDragging = false;
            divs.forEach((div) => {
                div.style.transition = ""; // 恢复动画平滑过渡
            });

            container.style.cursor = 'grab';
            console.log("触发");
        }

        // 鼠标进入暂停动画
        container.addEventListener("mouseenter", () => {
            divs.forEach((div) => {
                div.style.animationPlayState = "paused";
            });
            container.style.cursor = 'grab';
        });

        // 鼠标移开恢复动画并移除事件监听
        container.addEventListener("mouseleave", () => {
            divs.forEach((div) => {
                div.style.animationPlayState = "running";
            });
            console.log("鼠标移出");
            stopDragging(); // 确保停止拖动
            container.removeEventListener('mousemove', moveFunc);
        });



        // 计算拖动
        function moveFunc(e = null) {
            if (e) {
                if (!isDragging) return;
                const deltaY = e.pageY - startY; // 计算鼠标移动的距离
                const containerHeight = container.clientHeight;

            }
        }

        // 鼠标按下，开始拖动
        container.addEventListener('mousedown', (e) => {
            isDragging = true;
            startY = e.pageY;
            initialTranslateY = currentTranslateY;
            container.style.cursor = 'grabbing';

            divs.forEach((div) => {
                div.style.transition = "none"; // 暂停动画的平滑过渡
                div.style.animationPlayState = "pause";

            });
            container.addEventListener('mousemove', moveFunc);
        });

        // 鼠标抬起，停止拖动并恢复动画
        container.addEventListener('mouseup', () => {
            stopDragging();
            container.removeEventListener('mousemove', moveFunc);
        });



    });

</script>

</html>